package com.lzy.webapi.facade;

import com.lzy.framework.core.datasource.multiple.DataSource;
import com.lzy.framework.core.datasource.multiple.DataSourceHolder;
import com.lzy.payment.apis.PayApi;
import com.lzy.payment.dtos.pay.BasePayDTO;
import com.lzy.payment.dtos.pay.MobileRequestDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class PayFacade {
    @Autowired
    private PayApi payApi;

    public String alipayAsyNotify(BasePayDTO alipayPayDTO) {
        String responseContent = null;
        try {
            DataSourceHolder.setDataSource(DataSource.DATASOURCE_COMMON);
            responseContent = payApi.payAsyNotify(alipayPayDTO);
        }catch (Exception e){
            e.printStackTrace();
            throw e;
        }
        finally {
            DataSourceHolder.clearDataSource();
        }
        return responseContent;
    }

    public Map payRequestAll(MobileRequestDTO mrDTO) {
        Map map = new HashMap();
        try {
            DataSourceHolder.setDataSource(DataSource.DATASOURCE_COMMON);
            map = payApi.payRequestAll(mrDTO);
        }catch (Exception e){
            e.printStackTrace();
            throw e;
        }
        finally {
            DataSourceHolder.clearDataSource();
        }
        return map;
    }
}
